using ASP;
using HoWave.Common;
using HoWave.Data.Bll;
using HoWave.Data.Model;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Member_ClientRelation_ClientList : Member, IRequiresSessionState
{
	private string linkHead = "";
	protected Literal ltrPageTitle;
	protected TextBox txtClientName;
	protected Button SeachBut;
	protected GridView gvClient;
	protected Literal ltrPagePanel;
	protected HtmlForm clientForm;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			if (!base.OwnerPowerClientRelation(base.user.UserID))
			{
				this.Page.ClientScript.RegisterStartupScript(base.GetType(), "", "<script>alert('" + Language.GetMemberMsg("Common/RightErr", new string[0]) + "');window.close();</script>");
			}
			this.BindClient();
		}
	}
	protected void BindClient()
	{
		HoWave.Data.Bll.Client client = new HoWave.Data.Bll.Client();
		string query = this.GetQuery();
		int num = this.gvClient.PageIndex;
		if (Fetch.Get("pageindex") != null)
		{
			num = Convert.ToInt32(Fetch.GetID("pageindex").ToString());
			if (num == 0)
			{
				num = 1;
			}
		}
		int pageSize = this.gvClient.PageSize;
		int recordCount = client.GetRecordCount(query);
		int startIndex = (num - 1) * pageSize + 1;
		int endIndex = num * pageSize;
		DataTable dataSource = client.GetListByPage(query, "", startIndex, endIndex).Tables[0];
		this.gvClient.DataSource = dataSource;
		this.gvClient.DataBind();
		string url = "?1=1" + this.linkHead + "&pageindex";
		this.ltrPagePanel.Text = CurrPageLinks.instance.CurrPageLinkStr(num, pageSize, recordCount, "条记录&nbsp;&nbsp;每页&nbsp;" + pageSize + "&nbsp;条记录", url);
	}
	protected string GetQuery()
	{
		string text = " 1=1 ";
		if (base.Request.QueryString["TypeSelect"] != null)
		{
			string text2 = base.Request.QueryString["TypeSelect"];
			if (!string.IsNullOrEmpty(text2))
			{
				this.ltrPageTitle.Text = "选择对应客户";
				text = text + " and ClientType='" + text2 + "'";
				this.linkHead = this.linkHead + "&ClientType=" + text2;
			}
		}
		else
		{
			this.ltrPageTitle.Text = "选择上级联系人";
		}
		if (base.Request.QueryString["TypeSelectZhuCi"] != null)
		{
			string a = base.Request.QueryString["TypeSelectZhuCi"];
			if (a == "Zhu")
			{
				this.ltrPageTitle.Text = "选择主客户名称";
			}
			else
			{
				if (a == "Ci")
				{
					this.ltrPageTitle.Text = "选择从客户名称";
				}
			}
		}
		if (base.Request.QueryString["TypeSelectClientName"] != null)
		{
			string a = base.Request.QueryString["TypeSelectClientName"];
			if (a == "clientname")
			{
				this.ltrPageTitle.Text = "选择客户名称";
			}
		}
		if (base.Request.QueryString["ClientOwner"] != null)
		{
			string str = base.Request.QueryString["ClientOwner"];
			text = text + " and Owner ='" + str + "'";
			this.linkHead = this.linkHead + "&ClientName=" + str;
		}
		string text3 = this.txtClientName.Text.Trim();
		if (!string.IsNullOrEmpty(text3))
		{
			text = text + " and ClientName like '%" + text3 + "%'";
			this.linkHead = this.linkHead + "&ClientName=" + text3;
		}
		return text;
	}
	protected string GetDictionaryTitle(string fieldValue)
	{
		string result = "";
		HoWave.Data.Bll.Dictionary dictionary = new HoWave.Data.Bll.Dictionary();
		HoWave.Data.Model.Dictionary dictionary2 = dictionary.GetDictionary(fieldValue);
		if (dictionary2 != null)
		{
			result = dictionary2.FieldText;
		}
		return result;
	}
	protected void gvClient_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		if (e.Row.RowType == DataControlRowType.DataRow)
		{
			e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
			e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
		}
	}
	protected void gvClient_PageIndexChanging(object sender, GridViewPageEventArgs e)
	{
		this.gvClient.PageIndex = e.NewPageIndex;
		this.BindClient();
	}
	protected void SeachBut_Click(object sender, EventArgs e)
	{
		this.BindClient();
	}
}
